package com.prig.base.DTO.input;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.domain.Sort;
@ApiModel(value = "基本分页排序关键词类型",description = "基本分页排序关键词类型")
public class PageKeywordSortDto {
    @ApiModelProperty(value = "页码",example = "1")
    private int page=1;
    @ApiModelProperty(value = "页面个体数量",example = "10")
    private int limit=10;
    @ApiModelProperty(value = "关键词",example = "hello")
    private String keyword="";
    @ApiModelProperty(value = "排序字段",example = "id")
    private String field="id";
    @ApiModelProperty(value = "排序顺序",example = "asc")
    private String order="asc";

    public Sort getSort(){
        order = order.toUpperCase();
        Sort.Order sortOrder;
        if (order.equals("ASC")){
            sortOrder = new Sort.Order(Sort.Direction.ASC,field);
        }else{
            sortOrder = new Sort.Order(Sort.Direction.DESC,field);
        }
        return Sort.by(sortOrder);
    }

    public int getSQLPage() {
        return page-1;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }
}
